
package com.ce.cases.check.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.ce.cases.check.view.CaseSourceCheckView;
import com.ce.cases.source.view.CaseSourceView;
import com.ce.framework.datamaintain.action.SearchAction;
import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.DateUtil;
import com.ce.framework.util.StringUtil;
import com.ce.sys.login.model.User;
import com.ce.sys.org.dao.po.SysVOrg;
import com.ce.util.OrgUtil;


/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2014-03-28
* 创建时间：10:28:20
* 功能描述：检查情况登记 [CASE_SOURCE_CHECK]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class CaseSourceCheckSearchCondition2  extends SQLSearchCondition
	implements ISQLMapper
{

    private String taxpayerNum;
    private String involvedEnt;
    private String caseNum;
    private String recBeginDate;
    private String recEndDate;
    private String caseFrom;
    private String illegalType;
    private String inspectDept;
    private String collectDept;
    private String curOrgId;
    private String curPersonId;
    private String curOrgLevel;
    private String curOrgType;    
    private String curRootOrgId;
    private String curPersonPosition;//当前人职位
   
    @Override
   	public String getExcelName() {
   		return  "检查案源台账_"+DateUtil.format(new Date(),"yyyyMMddHHmm");
   	}
      
	@Override
	public void initCondition(SearchAction action, boolean search)
			throws AppException {
		User user=User.getUser(); 
		SysVOrg curOrg=OrgUtil.getOrg(User.getUserOrgId());
		this.curOrgId=curOrg.getVcId();
		this.curOrgLevel=curOrg.getVcOrgLevel();
		this.curPersonId=User.getUserId();//
		this.curOrgType=curOrg.getVcType();
		curRootOrgId=user.getRootOrgId();
		curPersonPosition=user.getVcPosition();
	}

	public String getSearchSql() throws AppException {
		
		StringBuffer sql = new StringBuffer("select t.vc_id as vcId,t.CASE_NUMBER,t.TAXPAYER_NUMBER,t.INVOLVED_ENTERPRICE,t.CASE_FROM_NAME,t.ILLEGAL_TYPE_NAME as illegalTypeName,c.*,work.VC_STATUS,work.VC_HANDLE_ORGNAME from CASE_SOURCE t,CASE_SOURCE_CHECK c,T_WORKFLOW_WORK work where t.vc_id=c.CASE_ID(+) and t.vc_id=VC_RECORD_ID and t.STATE=3 and to_number(work.VC_STATUS)>=2 and t.VC_DEL$FLAG = 0 ");
		
		//采用变量绑定的方式提高查询效率
		if(StringUtil.isNotBlank(taxpayerNum)){
			sql.append(" and t.taxpayer_number like ${taxpayerNum}||'%'");
		}
		if(StringUtil.isNotBlank(involvedEnt)){
			sql.append(" and t.involved_enterprice like '%'||${involvedEnt}||'%'");
		}
		if(StringUtil.isNotBlank(caseNum)){
			sql.append(" and t.case_number=${caseNum}");
		}
		sql.append(this.getDateCondition("receive_date", recBeginDate, recEndDate));
		if(StringUtil.isNotBlank(caseFrom)){
			sql.append(" and t.case_from_num=${caseFrom}");
		}
		if(StringUtil.isNotBlank(illegalType)){
			sql.append(" and t.illegal_type_num=${illegalType}");
		}
		if(StringUtil.isNotBlank(inspectDept)){
			sql.append(" and t.inspection_dept_id=${inspectDept}");
		}
		if(StringUtil.isNotBlank(collectDept)){
			sql.append(" and t.collection_dept_id=${collectDept}");
		}
		//排序
		if(StringUtil.isNotBlank(this.order)){
			if("registerDate".equals(sort)){
				sql.append(" order by t1."+ this.getOrderByUnderLine());
			}else{
				sql.append(" order by "+ this.getOrderByUnderLine());
			}
		}else{
			 sql.append(" order by t.register_date desc");
		}
		return sql.toString();
	}
	
	public Object fromSQLQuery(ResultSet rs, int num) {
		CaseSourceCheckView view = new CaseSourceCheckView();
		try {
			view.setVcId(rs.getString("vcId"));
			view.setCaseNumber(rs.getString("CASE_NUMBER"));
			view.setTaxpayerNumber(rs.getString("TAXPAYER_NUMBER"));
			view.setInvolvedEnterprice(rs.getString("INVOLVED_ENTERPRICE"));
			view.setCaseFromName(rs.getString("CASE_FROM_NAME"));
			
			view.setCheckHead(rs.getString("CHECK_HEAD"));
			view.setCheckPerson(rs.getString("CHECK_PERSON"));
			view.setPersonCount(rs.getInt("PERSON_COUNT"));
			view.setInspectionAdvice(rs.getString("INSPECTION_ADVICE"));
			view.setInvolvedMoney(rs.getDouble("INVOLVED_MONEY"));
			view.setTaxMoney(rs.getDouble("TAX_MONEY"));
			view.setBillCount(rs.getInt("BILL_COUNT"));
			view.setIllegalTypeNum(rs.getString("ILLEGAL_TYPE_NUM"));
			view.setIllegalTypeName(rs.getString("illegalTypeName"));
			view.setTakeStepsNum(rs.getString("TAKE_STEPS_NUM"));
			view.setTakeSteps(rs.getString("TAKE_STEPS"));
			view.setRegisterPerson(rs.getString("REGISTER_PERSON"));
			view.setRegisterDeptId(rs.getString("REGISTER_DEPT_ID"));
			view.setRegisterDate(rs.getDate("REGISTER_DATE"));
			
			
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return view;
	}
	
	public ISQLMapper getSQLMapper() {
		
		return this;
	}

	public String getTaxpayerNum() {
		return taxpayerNum;
	}

	public void setTaxpayerNum(String taxpayerNum) {
		this.taxpayerNum = taxpayerNum;
	}

	

	public String getInvolvedEnt() {
		return involvedEnt;
	}

	public void setInvolvedEnt(String involvedEnt) {
		this.involvedEnt = involvedEnt;
	}

	public String getCaseNum() {
		return caseNum;
	}

	public void setCaseNum(String caseNum) {
		this.caseNum = caseNum;
	}

	public String getRecBeginDate() {
		return recBeginDate;
	}

	public void setRecBeginDate(String recBeginDate) {
		this.recBeginDate = recBeginDate;
	}

	public String getRecEndDate() {
		return recEndDate;
	}

	public void setRecEndDate(String recEndDate) {
		this.recEndDate = recEndDate;
	}

	public String getCaseFrom() {
		return caseFrom;
	}

	public void setCaseFrom(String caseFrom) {
		this.caseFrom = caseFrom;
	}

	public String getIllegalType() {
		return illegalType;
	}

	public void setIllegalType(String illegalType) {
		this.illegalType = illegalType;
	}

	public String getInspectDept() {
		return inspectDept;
	}

	public void setInspectDept(String inspectDept) {
		this.inspectDept = inspectDept;
	}

	public String getCollectDept() {
		return collectDept;
	}

	public void setCollectDept(String collectDept) {
		this.collectDept = collectDept;
	}

	public String getCurOrgId() {
		curOrgId=User.getUserOrgId();
		return curOrgId;
	}

	public void setCurOrgId(String curOrgId) {
		this.curOrgId = curOrgId;
	}

	public String getCurPersonId() {
		
		return curPersonId;
	}

	public void setCurPersonId(String curPersonId) {
		this.curPersonId = curPersonId;
	}

	public String getCurOrgLevel() {
		
		return curOrgLevel;
	}

	public void setCurOrgLevel(String curOrgLevel) {
		this.curOrgLevel = curOrgLevel;
	}
	
	

}

